﻿<Page
    x:Class="SimpleShell.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SimpleShell"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="using:nRoute.Behaviors.Interactivity"
    xmlns:n="using:nRoute.Behaviors"
    xmlns:t="using:nRoute.Behaviors.Triggers"
    xmlns:c="using:nRoute.Components"
    xmlns:lb="using:SimpleShell.Behaviors"
    xmlns:nRoute="using:nRoute.Controls"
    mc:Ignorable="d">
    <Page.Resources>
        <c:ValueRelay x:Name="ViewServiceTypeRelay" Initialize="ViewServiceTypeRelay_Initialize_1" />
        <Storyboard x:Name="MessageStoryboard">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="MessageGrid">
				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-60">
					<EasingDoubleKeyFrame.EasingFunction>
						<QuarticEase EasingMode="EaseInOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0">
					<EasingDoubleKeyFrame.EasingFunction>
						<QuarticEase EasingMode="EaseInOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
				<EasingDoubleKeyFrame KeyTime="0:0:3.5" Value="0">
					<EasingDoubleKeyFrame.EasingFunction>
						<QuarticEase EasingMode="EaseInOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
				<EasingDoubleKeyFrame KeyTime="0:0:4" Value="-46">
					<EasingDoubleKeyFrame.EasingFunction>
						<QuarticEase EasingMode="EaseInOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MessageGrid">
				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:3.5" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0">
					<EasingDoubleKeyFrame.EasingFunction>
						<QuarticEase EasingMode="EaseInOut"/>
					</EasingDoubleKeyFrame.EasingFunction>
				</EasingDoubleKeyFrame>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>
	</Page.Resources>
    
    <i:Interaction.Behaviors>
        <n:BridgeViewModelBehavior  />
        <n:ViewServiceBehavior ViewServiceType="{Binding Value, Source={StaticResource ViewServiceTypeRelay}}" ViewServiceName="MessageViewService" IsDefault="True" />
    </i:Interaction.Behaviors>

    <Grid x:Name="RootGrid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        
        <!-- VSM -->
        <VisualStateManager.CustomVisualStateManager>
            <c:ExtendedVisualStateManager />
        </VisualStateManager.CustomVisualStateManager>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="NormalState">
                <VisualState x:Name="State0"/>
                <VisualState x:Name="State1">
                    <Storyboard>
                        <PointAnimation Duration="0" To="0.5,0.5" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="RootGrid" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0:0:2" To="0.50" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="RootGrid">
                            <DoubleAnimation.EasingFunction>
                                <QuarticEase EasingMode="EaseOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                        <DoubleAnimation Duration="0:0:2" To="0.75" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="RootGrid">
                            <DoubleAnimation.EasingFunction>
                                <QuarticEase EasingMode="EaseInOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                        <DoubleAnimation Duration="0:0:2" To="0.75" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="RootGrid">
                            <DoubleAnimation.EasingFunction>
                                <QuarticEase EasingMode="EaseInOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="State2">
                    <Storyboard>
                        <PointAnimation Duration="0" To="0.5,0.5" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="RootGrid" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0:0:2" To="-1"  Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="RootGrid">
                            <DoubleAnimation.EasingFunction>
                                <QuarticEase EasingMode="EaseOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="State3">
                    <Storyboard>
                        <PointAnimation Duration="0" To="0.5,0.5" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="RootGrid" d:IsOptimized="True"/>
                        <DoubleAnimation Duration="0:0:2" To="-1"  Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="RootGrid">
                            <DoubleAnimation.EasingFunction>
                                <QuarticEase EasingMode="EaseInOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        
        <!-- Setup -->
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition Width="400"/>
    		<ColumnDefinition Width="*"/>
    	</Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        
        <!-- Transform -->
        <Grid.RenderTransform>
            <CompositeTransform/>
        </Grid.RenderTransform>
        
		<!-- Background -->
        <Rectangle Fill="#50BBFE" />
        
		<!-- Header -->
        <Button x:Name="backButton" Style="{StaticResource BackButtonStyle}"
        	Margin="20,22,0,0" VerticalAlignment="Top">
        	<i:Interaction.Triggers>
        		<t:EventTrigger EventName="Click" >
        			<n:DirectionalNavigateAction Direction="Back"  />
        		</t:EventTrigger>
        	</i:Interaction.Triggers>
        </Button>

		<!-- Header -->
        <TextBlock Text="{Binding PageInfo.Title, ElementName=nContainer}" VerticalAlignment="Top" Style="{StaticResource PageHeaderTextStyle}" 
			HorizontalAlignment="Left" Margin="80,22,0,0" FontSize="36" />
        
		<!-- Buttons -->
        <StackPanel HorizontalAlignment="Left"  VerticalAlignment="Top" Orientation="Vertical" Height="Auto" Width="Auto" Margin="12,85,0,0">
            <Button Width="180" Height="60" Content="Navigate to Page A" Margin="2">
                <i:Interaction.Triggers>
                	<t:EventTrigger EventName="Click">
                		<n:NavigateAction Url="Content/PageA" />
                	</t:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Width="180" Height="60" Content="Navigate to Page B" Margin="2">
                <i:Interaction.Triggers>
                	<t:EventTrigger EventName="Click">
                		<n:NavigateAction Url="Content/PageB" />
                	</t:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Width="180" Height="60" Content="Navigate to Page C" Margin="2">
                <i:Interaction.Triggers>
                	<t:EventTrigger EventName="Click">
                		<n:NavigateAction Url="Content/PageC" />
                	</t:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Height="60" Content="Navigate to Non-Existent Page" Margin="2">
                <i:Interaction.Triggers>
                	<t:EventTrigger EventName="Click">
                		<n:NavigateAction Url="Content/NonExistentPage" />
                	</t:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            
            <HyperlinkButton Margin="2" Content="Goto Default State">
                <i:Interaction.Triggers>
                    <t:EventTrigger EventName="Click">
                        <n:GoToStateAction TargetName="RootGrid" StateName="State0" />
                    </t:EventTrigger>
                </i:Interaction.Triggers>
            </HyperlinkButton>
            
            <HyperlinkButton Margin="2" Content="Goto VSM State 1">
                <i:Interaction.Triggers>
                    <t:EventTrigger EventName="Click">
                        <n:GoToStateAction TargetName="RootGrid" StateName="State1" />
                    </t:EventTrigger>
                </i:Interaction.Triggers>
            </HyperlinkButton>

            <HyperlinkButton Margin="2" Content="Goto VSM State 2">
                <i:Interaction.Triggers>
                    <t:EventTrigger EventName="Click">
                        <n:GoToStateAction TargetName="RootGrid" StateName="State2" />
                    </t:EventTrigger>
                </i:Interaction.Triggers>
            </HyperlinkButton>

            <HyperlinkButton Margin="2" Content="Goto VSM State 3">
                <i:Interaction.Triggers>
                    <t:EventTrigger EventName="Click">
                        <n:GoToStateAction TargetName="RootGrid" StateName="State3" />
                    </t:EventTrigger>
                </i:Interaction.Triggers>
            </HyperlinkButton>
            
            <ItemsControl x:Name="PageCommandsControl" ItemsSource="{Binding PageInfo.PageCommands, ElementName=nContainer}" >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Content="{Binding Label}" MinWidth="180">
                            <i:Interaction.Behaviors>
                                <n:BoolValueDisableBehavior ValueBinding="{Binding IsEnabled}" Negate="True" />
                                <n:BoolValueVisibilityBehavior ValueBinding="{Binding IsVisible}" />
                            </i:Interaction.Behaviors>
                            <i:Interaction.Triggers>
                                <t:EventTrigger EventName="Click">
                                    <n:ExecuteVisualCommandAction VisualCommandBinding="{Binding }" />
                                </t:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            
        </StackPanel>
		
		<!-- Navigation Container -->
        <nRoute:BrowsingContainer x:Name="nContainer" Grid.Column="1" Url="about:blank">
            <i:Interaction.Behaviors>
            	<n:NavigationHandlerBehavior IsDefaultHandler="True" />
            </i:Interaction.Behaviors>
            <!--<i:Interaction.Triggers>
                <lb:SlideBackGestureTrigger>
                    <n:DirectionalNavigateAction Direction="Back" />
                </lb:SlideBackGestureTrigger>
             </i:Interaction.Triggers>-->
        </nRoute:BrowsingContainer>

		<!-- Mem Usage Info -->
        <TextBlock Text="Memory Usage:" VerticalAlignment="Bottom" Style="{StaticResource PageSubheaderTextStyle}" 
			HorizontalAlignment="Left" Margin="14,0,0,110" Height="40" />
        <TextBlock Text="{Binding MemoryUsage}" VerticalAlignment="Bottom" Style="{StaticResource PageSubheaderTextStyle}" 
			HorizontalAlignment="Left" Margin="14,0,0,75" Height="40" Foreground="#DE000000" />

        <Button Height="60" Content="Start" Margin="12,10,10,10" VerticalAlignment="Bottom">
            <i:Interaction.Triggers>
                <t:EventTrigger EventName="Click">
                    <n:ExecuteCommandAction CommandBinding="{Binding StartMemCommand}" ManageEnableState="True" />
                </t:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
        <Button Height="60" Content="Stop" Margin="80,10" VerticalAlignment="Bottom">
            <i:Interaction.Triggers>
                <t:EventTrigger EventName="Click">
                	<n:ExecuteCommandAction CommandBinding="{Binding StopMemCommand}" ManageEnableState="True" />
                </t:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
        <Button Height="60" Content="GC Now" Margin="146,10" VerticalAlignment="Bottom"  Command="{Binding GCCommand}"/>


		<Grid x:Name="MessageGrid" Background="#FF9B9B9B" Height="46" VerticalAlignment="Top" Grid.ColumnSpan="2" RenderTransformOrigin="0.5,0.5" Opacity="0">
			<Grid.RenderTransform>
				<CompositeTransform TranslateY="-46"/>
			</Grid.RenderTransform>
			<TextBlock x:Name="MessageText" Margin="12,12,12,0" FontSize="21.333" TextTrimming="WordEllipsis" VerticalAlignment="Top" />
		</Grid>
    </Grid>
</Page>
